<?php

declare (strict_types=1);

namespace app\store\controller\customer;

use app\store\controller\Controller;
use think\App;
use think\response\Json;

/**
 * Class Service
 * @package app\store\controller\customer
 */
class Service extends Controller
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new \app\store\model\customer\Service();
    }

    /**
     * 列表
     * @return Json
     * @throws \think\db\exception\DbException
     */
    public function list(): Json
    {
        $list = $this->model->getList($this->request->param(),$this->store);
        return $this->renderSuccess(is_array($list) ? $list : compact('list'));
    }

    /**
     * 添加
     * @return Json
     */
    public function add(): Json
    {
        if ($this->model->adds($this->postForm(), $this->store)) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($this->model->getError() ?: '添加失败');
    }

}
